/*
 * Filename    : SceneMenu.java
 * Projectname : CobaScene
 * Date        : Jan 1, 2013 , 9:01:38 PM 
 * 
 */

package com.example.cobascene.scene;

import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.entity.scene.IOnAreaTouchListener;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.util.color.Color;

import android.graphics.Typeface;
import android.util.Log;

import com.example.cobascene.IManageableScene;
import com.example.cobascene.SceneManager;
import com.example.cobascene.config.Game_Data;
import com.example.cobascene.config.Game_Define;

public class SceneMenu extends Scene implements IManageableScene, Game_Define, Game_Data, IOnAreaTouchListener
{
	private BaseGameActivity	activity;
	private SceneManager		sm;

	private Font				mFont;
	private Text				txtStart;

	public SceneMenu(BaseGameActivity pActivity)
	{
		// TODO Auto-generated constructor stub
		activity = pActivity;
		sm = new SceneManager(activity);
		setOnAreaTouchListener(this);
		loadResources();
		applyResources();
		registerUpdateHandler();
	}

	@Override
	public void loadResources()
	{
		// TODO Auto-generated method stub
		mFont = FontFactory.create(activity.getFontManager(), activity.getTextureManager(), 256, 256,
				Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);
		mFont.load();

	}

	@Override
	public void applyResources()
	{
		// TODO Auto-generated method stub
		setBackground(new Background(Color.PINK));
		txtStart = new Text(0, 0, mFont, "Start", activity.getVertexBufferObjectManager());
		txtStart.setPosition(RES_WIDTH / 2 - txtStart.getWidth() / 2, RES_HEIGHT / 2 - txtStart.getHeight() / 2);
		attachChild(txtStart);
		this.registerTouchArea(txtStart);

	}

	@Override
	public void registerUpdateHandler()
	{
		// TODO Auto-generated method stub
		this.registerUpdateHandler(new IUpdateHandler()
		{

			@Override
			public void reset()
			{
				// TODO Auto-generated method stub

			}

			@Override
			public void onUpdate(float pSecondsElapsed)
			{
				// TODO Auto-generated method stub

			}
		});

	}

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea, float pTouchAreaLocalX,
			float pTouchAreaLocalY)
	{
		// TODO Auto-generated method stub
		if (pTouchArea.equals(txtStart))
		{
			sm.setScene(SceneManager.SCENE_GAMEPLAY);
		}
		return false;
	}

	@Override
	public void unloadResources()
	{
		// TODO Auto-generated method stub

	}

}
